<template>
  <div class="box">
    <div class="title">
      <p>年龄比例</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <!-- 图形图表的容器 -->
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts" name="Age">
// 引入echarts
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'
// 获取DOM
let charts = ref()

// 组件挂载完毕初始化图形图表
onMounted(() => {
  // 初始化echarts
  let myChart = echarts.init(charts.value)
  // 配置myChart
  myChart.setOption({
    /* title: {
      text: '今日年龄比例',
      left: '100',
      top: '30',
      textStyle: {
        color: '#fff',
        fontStyle: 'normal',
      },
    }, */
    // 提示框组件
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)',
      textStyle: {
        color: 'black',
        fontSize: 18,
      },
    },
    // 图例组件
    legend: {
      left: '30', // 位置
      top: '40',
      orient: 'vertical', // 组件方向为垂直
      // 文本样式
      textStyle: {
        color: 'white',
        fontSize: 18,
        // 行高
        lineHeight:22,
      },
    },
    series: [
      {
        name: '年龄比例',
        type: 'pie',
        radius: [20, 160],
        center: ['55%', '55%'],
        roseType: 'area',
        itemStyle: {
          borderRadius: 5,
        },
        // 不显示标签
        label: {
          show: false,
          position: 'inside',
          fontSize:"15"
        },
        // 数据
        data: [
          { value: 2000, name: '20-25岁' },
          { value: 1800, name: '25-30岁' },
          { value: 1600, name: '30-35岁' },
          { value: 1400, name: '35-40岁' },
          { value: 1200, name: '18-20岁' },
          { value: 1000, name: '40-50岁' },
          { value: 800, name: '12-18岁' },
          { value: 600, name: '50岁以上' },
        ],
      },
    ],
    // 图形布局占满全部容器
    grid: {
      left: 0,
      top: 0,
      bottom: 0,
      right: 0,
    },
  })
})
</script>

<style scoped lang="scss">
.box {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 100%;
  .title {
    margin-left: 20px;
    position: relative;
    top:25px;
    p {
      color: white;
      font-size: 20px;
    }
  }
  .charts {
    height: 300px;
  }
}
</style>
